package com.tangji.signaltower.task;

import com.tangji.signaltower.runners.SocketClientRunner;
import com.tangji.signaltower.runners.WSClient;
import com.tangji.signaltower.runners.client.ForexPoNettyClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

/**
 * Created with IntelliJ IDEA.
 * User: sm
 * Date: 2021/7/16
 * Time: 1:55 下午
 * <p>
 * 用于检测数据源是否暂停
 */
@Service
public class DataSourceCheckTask {
    private static final Logger logger = LoggerFactory.getLogger(DataSourceCheckTask.class);

    public static int lastMsgNum = -100;

    /**
     * 每3秒检测一次数据
     */
//    @Scheduled(cron = "0/3 * * * * ?")
    public void check() {
        logger.info("== 开始检测数据源 ==,lastMsgNum:" + lastMsgNum + " WSClient.msgNum:" + WSClient.msgNum);
        if (lastMsgNum == -100) {
            lastMsgNum = WSClient.msgNum;
            return;
        }

        if (WSClient.msgNum == lastMsgNum) {
            logger.error("== 用于检测数据源是否暂停 开始检测数据源 没有再接收到数据源的数据 ==");
//            ForexPoNettyClient.getInst().startConnectServerAlways(System.currentTimeMillis() + "");
        } else {
            lastMsgNum = WSClient.msgNum;
        }

    }
}
